<?php

namespace App\Model\Steam;
use App\DB\Steam\SteamGameDB;
use App\Model\Common;
use Illuminate\Database\Eloquent\Model;

class SteamGame extends Model
{
    protected $table = 'steam_game';
    public $timestamps = false;

    /**
     * 精品推荐
     *
     * @param $id
     * @param $start
     * @param $limit
     * @return mixed
     */
    public static function recommendGame($page, $limit)
    {
        $result = self::select('id', 'title', 'issue_date', 'price', 'is_new', 'is_recommend', 'thumb')
            ->where('is_recommend', 1)->where('is_delete', 0)
            ->orderBy('issue_date', 'desc');
        $gameList = Common::page($result, $page, $limit);
        if(!$gameList) {
            return false;
        }
        $gameList['data'] = SteamGamePicture::getListPicture($gameList['data']);
        return $gameList;
    }

    
    /**
     * 特别优惠
     *
     * @param $id
     * @param $start
     * @param $limit
     * @return mixed
     */
    public static function preferentialGame($page, $limit)
    {
        $result = self::select('id', 'title', 'issue_date', 'price', 'discount_price', 'discount_start', 'discount_end', 'thumb')
            ->where('is_discount', 1)->where('is_delete', 0)
            ->orderBy('discount_end', 'acs');
        $gameList = Common::page($result, $page, $limit);
        if(!$gameList) {
            return false;
        }
        return $gameList;
    }

    

    /**
     * 详情列表
     *
     * @param $id
     * @param $start
     * @param $limit
     * @return mixed
     */
    public static function detailList($tab, $page, $limit)
    {
        $result = self::select('id', 'title', 'issue_date', 'price', 'is_discount', 'discount_price', 'discount_start', 'discount_end', 'thumb', 'is_windows', 'is_macos', 'is_linux', 'is_free')
            ->where('is_delete', 0);
        switch ($tab) {
            case 'new':
                $result = $result->where('is_new', 1)->orderBy('issue_date', 'desc');
                break;
            case 'hot':
                $result = $result->where('is_hot', 1)->orderBy('issue_date', 'desc');
                break;
            case 'soon':
                $result = $result->where('issue_date', '>', currentTime())->orderBy('issue_date', 'asc');
                break;
            case 'discount':
                $result = $result->where('is_discount', 1)->orderBy('discount_end', 'asc');
                break;
            default:
                $result = $result->orderBy('issue_date', 'desc');
                break;
        }
        $gameList = Common::page($result, $page, $limit);
        if(!$gameList) {
            return false;
        }
        $gameList['data'] = SteamGamePicture::getListPicture($gameList['data']);
        $gameList['data'] = SteamGameDB::getListTag($gameList['data']);
        return $gameList;
    }

}